package operation;

import book.BookList;

import book.Book;
import java.util.Scanner;

public class AddOperation implements IOperation{
    @Override
    public void work( BookList bookList) {

//        Scanner scanner=new Scanner(System.in);
//
//        System.out.println("请输入要增加的书名：");
//        String name=scanner.nextLine();
//        System.out.println("请输入要增加的作者名：");
//        String author=scanner.nextLine();
//        System.out.println("请输入要增加的价格：");
//        int price=scanner.nextInt();
//        System.out.println("请输入要增加的类型：");
//        String type=scanner.nextLine();
//        Book book=new Book(name,author,price,type);
//
//        int size= bookList.getUsedSize()+1;
//
//        bookList.setBooks(size,book);
//        bookList.setUsedSize(size);
//        System.out.println("新增成功！");

        System.out.println("新增图书！");
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入图书的名字：");
        String name = scanner.nextLine();
        System.out.println("请输入图书的作者:");
        String author = scanner.nextLine();
        System.out.println("请输入图书的类型:");
        String type = scanner.nextLine();
        System.out.println("请输入图书的价格:");
        int price = scanner.nextInt();

        Book book = new Book(name,author,price,type);

        int currentSize = bookList.getUsedSize();

        bookList.setBooks(currentSize,book);

        bookList.setUsedSize(currentSize+1);

        System.out.println("新增书籍成功！");
    }
}
